<extend name='Public/demo' />

<block name='contents'>
<div class="row">
                  <div class="col-lg-12">
                      <!--widget start-->
                      <section class="panel">
                          <div class="twt-feed blue-bg">
                              <h1><?php echo $_SESSION['home']['nickname'] ?></h1>
                              <p><?php echo $_SESSION['home']['uname'] ?></p>
                              <a href="#">
                                  <img src="__PUBLIC__<?php echo $_SESSION['home']['photo'] ?>" alt="">
                              </a>
                          </div>
                          <div class="weather-category twt-category">
                              <ul>
                                  <li class="active">
                                      <h5>{$grade}</h5>
                                      当前等级
                                  </li>
                                  <li>
                                      <h5>{$exp}</h5>
                                      当前经验
                                  </li>
                                  <li>
                                      <h5>{$vipday}</h5>
                                      会员剩余时间
                                  </li>
                              </ul>
                          </div>
                          <footer class="twt-footer">
                              <button class="btn btn-space btn-white buyvip" data-toggle="button">
                                  <i class="icon-dollar"></i> 购买会员
                              </button>
                              <a class="btn btn-space btn-info pull-right" type="button" href="{:U('Vip/show')}">
                                  <i class="icon-dropbox"></i> 会员特权
                              </a>
                          </footer>
                      </section>
                      <!--widget end-->
                      <section >
                      <!-- 购买会员 S-->
                        <div class="col-lg-12 buypay" style="display:none">
                                <div class="col-md-4" style="text-align:center;">
                                    购买前请先关注该微信公众号<br>
                                    <img src="__PUBLIC__/Resource/wechat.jpg" style="width:50%">
                                </div>
                                <div class="col-md-6 col-md-offset-1 buyarea">
                                <form action="">
                                    请输入需要购买会员的时限 ( ps:10元/月 )<br><br>
                                    <input type="number" class="form-control buynum" max="24" min="1" placeholder="请输入需要购买会员的时限   1<= num<=24">
                                    <br>
                                    <button class="btn btn-default btnbuy">点击购买</button>
                                </form>
                                </div>
                        </div>
                      <!-- 购买会员 E-->
                      </section>
                  </div>
</div>

                    <script type="text/javascript">
                    var init = null;
                        $('.buyvip').toggle(function(){
                            //点击出现会员购买页面
                            $('.buypay').siblings().css('display','none');
                            $('.buypay').fadeIn(1500);
                        },function(){
                            //点击隐藏会员购买页面
                            $('.buypay').siblings().css('display','none');
                            $('.buypay').fadeOut(500);
                        });

                        //当点击购买按钮时
                        $('.btnbuy').click(function(){
                            //得到当前的文本框中的数字
                            var buynum = $('.buynum').val();
                            //生成一个随机数
                            var rnum =parseInt( Math.random() * 100000);

                            //发送ajax
                            $.post("{:U('Vip/ewm')}",{'buynum':buynum,'rnum':rnum},function(data){
                                if (data == 'no') {
                                    $('.buynum').val('');
                                    $('.buynum').attr('placeholder','请输入合法的数字!');
                                }else{
                                    $('.buyarea').html('请扫描此二维码完成购买 : <br>' + data['img']);
                                }
                            });
                            //启动定时器
                            init = setInterval(function(){
                              //发送ajax
                              // console.log(rnum);
                              $.post("{:U('Vip/gangRape')}",{'rnum':rnum},function(data){
                                if (data == 'yes') {
                                  $('.buyarea').html('<div class="alert alert-block alert-danger fade in">\n\
                                      <button data-dismiss="alert" class="close close-sm" type="button">\n\
                                          <i class="icon-remove"></i>\n\
                                      </button>\n\
                                      <strong>叮咚!</strong>尊敬的会员~您好~ 您已成功充值~\n\
                                  </div>');
                                  clearInterval(init);
                                }
                              });
                            },1000);

                            //支付失效
                            // setTimeout(function(){
                            //   clearInterval(init);
                            //   $('.buyarea').html('<div class="alert alert-block alert-danger fade in">\n\
                            //       <button data-dismiss="alert" class="close close-sm" type="button">\n\
                            //           <i class="icon-remove"></i>\n\
                            //       </button>\n\
                            //       <strong>我要报警了 你调戏我~!</strong> 二维码验证失效~请刷新重新得到付款二维码~\n\
                            //   </div>');
                            // },30000);
                            return false;
                        })
                    </script>
</block>
